package com.ccys.cms.service.thinkWell.impl;


import com.ccys.cms.service.thinkWell.TblPhqScoringWebService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.thinkWell.TblPhqScoringDTO;
import com.ccys.db.entity.TblPhqScoring;
import com.ccys.db.mapper.TblPhqScoringMapper;
import com.ccys.db.page.PageUtils;
import com.ccys.db.rely.service.impl.BaseServiceImpl;
import com.ccys.db.vo.thinkWell.TblPhqScoringWebVO;

import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;


/**
 * tbl_phq_scoring管理
 */
@Service
@Slf4j
public class TblPhqScoringWebServiceImpl extends BaseServiceImpl<TblPhqScoring> implements TblPhqScoringWebService {

    @Autowired(required = false)
    private TblPhqScoringMapper tblPhqScoringMapper;

    @Override
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, TblPhqScoringDTO dto) {
        if(StringUtils.isEmpty(dto.getPhqId())) {
            return ResponseResult.error("phqId is not null");
        }
        PageUtils.startPage(request);
        List<TblPhqScoringWebVO> list = this.tblPhqScoringMapper.listObjectsCms(dto);
        PageInfo pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo);
    }


    @Override
    public ResponseResult change(List<TblPhqScoring> dto) {
        if(dto != null && !dto.isEmpty()) {
            for (TblPhqScoring scoring : dto) {
                if(StringUtils.isEmpty(scoring.getId())) {
                    return ResponseResult.error("id is not null");
                }
                this.updateEntityById(scoring);
            }
        }
        return ResponseResult.success();
    }




}